package com.lcw.library.imagepicker.manager;

import com.lcw.library.imagepicker.utils.ImageLoader;

import java.util.ArrayList;

/**
 * 图片选择器统一配置管理类
 * 
 * 使用单例模式管理所有配置参数，包括：
 * - 界面标题
 * - 相机显示开关
 * - 图片/视频显示开关
 * - GIF过滤开关
 * - 选择模式（单选/多选）
 * - 最大选择数量
 * - 单类型选择模式
 * - 权限说明弹窗开关
 * - 图片加载器
 * - 历史选择记录
 * 
 */
public class ConfigManager {

    public static final int SELECT_MODE_SINGLE = 0;
    public static final int SELECT_MODE_MULTI = 1;

    private String title;//标题
    private boolean showCamera = false;//是否显示拍照Item，默认不显示
    private boolean showImage = true;//是否显示图片，默认显示
    private boolean showVideo = true;//是否显示视频，默认显示
    private boolean filterGif = false;//是否过滤GIF图片，默认不过滤
    private int selectionMode = SELECT_MODE_SINGLE;//选择模式，默认单选
    private int maxCount = 1;//最大选择数量，默认为1
    private int maxVideoCount = 1;//最大选择视频数量，默认为1
    private boolean singleType;//是否只支持选单类型（图片或者视频）
    private boolean showPermissionDialog = true;//是否显示权限说明弹窗，默认显示
    private ArrayList<String> imagePaths;//上一次选择的图片地址集合

    private ImageLoader imageLoader;

    private static volatile ConfigManager mConfigManager;

    private ConfigManager() {
    }

    /**
     * 获取ConfigManager单例实例
     * 
     * @return ConfigManager实例
     */
    public static ConfigManager getInstance() {
        if (mConfigManager == null) {
            synchronized (ConfigManager.class) {
                if (mConfigManager == null) {
                    mConfigManager = new ConfigManager();
                }
            }
        }
        return mConfigManager;
    }

    /**
     * 获取标题
     * 
     * @return 标题字符串
     */
    public String getTitle() {
        return title;
    }

    /**
     * 设置标题
     * 
     * @param title 标题字符串
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * 是否显示相机
     * 
     * @return true显示，false不显示
     */
    public boolean isShowCamera() {
        return showCamera;
    }

    /**
     * 设置是否显示相机
     * 
     * @param showCamera true显示，false不显示
     */
    public void setShowCamera(boolean showCamera) {
        this.showCamera = showCamera;
    }

    /**
     * 是否显示图片
     * 
     * @return true显示，false不显示
     */
    public boolean isShowImage() {
        return showImage;
    }

    /**
     * 设置是否显示图片
     * 
     * @param showImage true显示，false不显示
     */
    public void setShowImage(boolean showImage) {
        this.showImage = showImage;
    }

    /**
     * 是否显示视频
     * 
     * @return true显示，false不显示
     */
    public boolean isShowVideo() {
        return showVideo;
    }

    /**
     * 设置是否显示视频
     * 
     * @param showVideo true显示，false不显示
     */
    public void setShowVideo(boolean showVideo) {
        this.showVideo = showVideo;
    }

    public int getMaxCount() {
        return maxCount;
    }

    public void setMaxCount(int maxCount) {
        if (maxCount > 1) {
            setSelectionMode(SELECT_MODE_MULTI);
        }
        this.maxCount = maxCount;
    }

    public int getMaxVideoCount() {
        return maxVideoCount;
    }

    public void setMaxVideoCount(int maxVideoCount) {
        if (maxVideoCount > 1) {
            setSelectionMode(SELECT_MODE_MULTI);
        }
        this.maxVideoCount = maxVideoCount;
    }

    public boolean isFilterGif() {
        return filterGif;
    }

    public void setFilterGif(boolean filterGif) {
        this.filterGif = filterGif;
    }

    public int getSelectionMode() {
        return selectionMode;
    }

    public void setSelectionMode(int mSelectionMode) {
        this.selectionMode = mSelectionMode;
    }

    public ArrayList<String> getImagePaths() {
        return imagePaths;
    }

    public void setImagePaths(ArrayList<String> imagePaths) {
        this.imagePaths = imagePaths;
    }

    public ImageLoader getImageLoader() throws Exception {
        if (imageLoader == null) {
            throw new Exception("imageLoader is null");
        }
        return imageLoader;
    }

    public boolean isSingleType() {
        return singleType;
    }

    public void setSingleType(boolean singleType) {
        this.singleType = singleType;
    }

    /**
     * 是否显示权限说明弹窗
     * 
     * @return true显示，false不显示
     */
    public boolean isShowPermissionDialog() {
        return showPermissionDialog;
    }

    /**
     * 设置是否显示权限说明弹窗
     * 
     * @param showPermissionDialog true显示，false不显示
     */
    public void setShowPermissionDialog(boolean showPermissionDialog) {
        this.showPermissionDialog = showPermissionDialog;
    }

    public void setImageLoader(ImageLoader imageLoader) {
        this.imageLoader = imageLoader;
    }
}
